package com.pureut.production.controller;


import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.dto.GroupManagementDto;
import com.pureut.production.service.GroupManagementService;
import com.pureut.production.domain.vo.GroupManagementVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 班组管理
 *
 * @author: CM
 * @date: 2023/2/7  16:16
 */
@RestController
@RequestMapping("/group")
public class GroupManagementController extends BaseController {

    @Resource
    private GroupManagementService groupManagementService;

    /**
     * 班组管理新增
     */
    @RequiresPermissions("productionTube:shopAdministration:team:add")
    @Log(title = "新增班组", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody GroupManagementVo groupManagementVo) {
        return toAjax(groupManagementService.add(groupManagementVo));
    }

    /**
     * 班组管理修改
     */
    @RequiresPermissions("productionTube:shopAdministration:team:edit")
    @Log(title = "修改班组", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody GroupManagementVo groupManagementVo) {
        return toAjax(groupManagementService.edit(groupManagementVo));
    }

    /**
     * 班组管理删除
     */
    @RequiresPermissions("productionTube:shopAdministration:team:remove")
    @Log(title = "班组管理删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable("ids") String ids) {
        return toAjax(groupManagementService.remove(ids));
    }


    /**
     * 班组信息列表查询
     */
    @RequiresPermissions("productionTube:shopAdministration:team:list")
    @GetMapping("/list")
    public TableDataInfo getList(GroupManagementVo groupManagementVo) {
        startPage();
        //查询库存列表
        List<GroupManagementDto> list = groupManagementService.getList(groupManagementVo);
        return getDataTable(list);
    }

    /**
     * 查看单据
     */
    @RequiresPermissions("productionTube:shopAdministration:team:query")
    @GetMapping("/view/{id}")
    public AjaxResult view(@PathVariable("id") Long id) throws Exception {
        return AjaxResult.success(groupManagementService.view(id));
    }


    /**
     * 获取车间id
     */
    @GetMapping("/getWorkshopId")
    public AjaxResult getWorkshopId() {
        return AjaxResult.success(groupManagementService.getWorkshopId());
    }

    /**
     * 根据班组编码获取班组信息，班长信息及班组成员（设备模块fegin调用）
     */
    @GetMapping("/getDataByGroupCode")
    public AjaxResult getDataByGroupCode(String groupCode) {
        return AjaxResult.success(groupManagementService.getDataByGroupCode(groupCode));
    }



}
